package com.neo.test.juc;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @author Kisen
 * @email lqs0911@qq.com
 * @date 2023/3/7 23:20
 * @detail
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        Thread threadA = new Thread(() -> {
//            try {
//                TimeUnit.SECONDS.sleep(2);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
            System.out.println(Thread.currentThread().getName() + " come in. " + System.currentTimeMillis());
            LockSupport.park();
            System.out.println(Thread.currentThread().getName() + " 唤醒. " + System.currentTimeMillis());

        }, "Thread A");
        threadA.start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            LockSupport.unpark(threadA);
            System.out.println(Thread.currentThread().getName() + " 通知.");
        }, "Thread B").start();
    }
}
